<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="JinYan&#39;s blog">
  <meta name="keyword" content="hexo-theme, vuejs">
  
    <link rel="shortcut icon" href="/blog/css/images/logo.jpg">
  
  <title>
    
      Python-3-文件操作 | SanYuanEmpire
    
  </title>
  <link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdn.bootcss.com/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdn.bootcss.com/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/blog/css/style.css">
<link rel="stylesheet" href="/blog/css/plugins/gitment.css">
  <script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdn.bootcss.com/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdn.bootcss.com/nprogress/0.2.0/nprogress.min.js"></script>
  <script src="/blog/js/qrious.js"></script>
<script src="/blog/js/gitment.js"></script>
  
  
    <!-- MathJax support START -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <!-- MathJax support END -->
  


</head>
<div class="wechat-share">
  <img src="/css/images/logo.jpg" />
</div>

  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/blog/">
      <div class="logo"></div>
      <span>SanYuanEmpire</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/blog/" class="item-link">Home</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/blog/archives/" class="item-link">Archives</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/blog/" class="menu-link">Home</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/blog/archives/" class="menu-link">Archives</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>Python-3-文件操作</h2>
  <p class="post-date">2018-09-03</p>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h1 id="文件操作"><a href="#文件操作" class="headerlink" title="文件操作"></a>文件操作</h1><h2 id="打开文件"><a href="#打开文件" class="headerlink" title="打开文件"></a>打开文件</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">open() 函数用于打开/创建一个文件，并返回一个 file 对象：</span><br><span class="line">open(filename, mode)</span><br><span class="line">•	filename：包含了你要访问的文件名称的字符串值</span><br><span class="line">•	mode：决定了打开文件的模式：只读，写入，追加等</span><br></pre></td></tr></table></figure>
<p><img src="http://wx2.sinaimg.cn/mw690/705e8c43gy1fuw5gy1pv6j20jm0gptc8.jpg" alt="文件打开模式"></p>
<h1 id="文件对象方法"><a href="#文件对象方法" class="headerlink" title="文件对象方法"></a>文件对象方法</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">fileObject.close()</span><br><span class="line">close() 方法用于关闭一个已打开的文件。关闭后的文件不能再进行读写操作，否则会触发 ValueError 错误。 close() 方法允许调用多次。</span><br><span class="line">当 file 对象，被引用到操作另外一个文件时，Python 会自动关闭之前的 file 对象。 使用 close() 方法关闭文件是一个好的习惯。</span><br><span class="line">fileObject.flush()</span><br><span class="line">flush() 方法是用来刷新缓冲区的，即将缓冲区中的数据立刻写入文件，同时清空缓冲区，不需要是被动的等待输出缓冲区写入。</span><br><span class="line">一般情况下，文件关闭后会自动刷新缓冲区，但有时你需要在关闭前刷新它，这时就可以使用 flush() 方法。</span><br><span class="line">fileObject.fileno()</span><br><span class="line">fileno() 方法返回一个整型的文件描述符(file descriptor FD 整型)，可用于底层操作系统的 I/O 操作。</span><br><span class="line">fileObject.isatty()</span><br><span class="line">isatty() 方法检测文件是否连接到一个终端设备，如果是返回 True，否则返回 False。</span><br><span class="line">next(iterator[,default])</span><br><span class="line">Python 3 中的 File 对象不支持 next() 方法。 Python 3 的内置函数 next() 通过迭代器调用 __next__() 方法返回下一项。在循环中，next() 函数会在每次循环中调用，该方法返回文件的下一行，如果到达结尾(EOF)，则触发 StopIteration。</span><br><span class="line">fileObject.read()</span><br><span class="line">read() 方法用于从文件读取指定的字节数，如果未给定或为负则读取所有。</span><br><span class="line">fileObject.readline()</span><br><span class="line">readline() 方法用于从文件读取整行，包括 “\n” 字符。如果指定了一个非负数的参数，则返回指定大小的字节数，包括 “\n” 字符。</span><br><span class="line">fileObject.readlines()</span><br><span class="line">readlines() 方法用于读取所有行(直到结束符 EOF)并返回列表，该列表可以由 Python 的 for... in ... 结构进行处理。如果碰到结束符 EOF，则返回空字符串。</span><br><span class="line">fileObject.seek(offset[, whence])</span><br><span class="line">seek() 方法用于移动文件读取指针到指定位置。</span><br><span class="line">whence 的值, 如果是 0 表示开头, 如果是 1 表示当前位置, 2 表示文件的结尾。whence 值为默认为0，即文件开头。例如：</span><br><span class="line">seek(x, 0)：从起始位置即文件首行首字符开始移动 x 个字符</span><br><span class="line">seek(x, 1)：表示从当前位置往后移动 x 个字符</span><br><span class="line">seek(-x, 2)：表示从文件的结尾往前移动 x 个字符</span><br><span class="line">fileObject.tell(offset[, whence])</span><br><span class="line">tell() 方法返回文件的当前位置，即文件指针当前位置。</span><br><span class="line">fileObject.truncate([size])</span><br><span class="line">truncate() 方法用于从文件的首行首字符开始截断，截断文件为 size 个字符，无 size 表示从当前位置截断；截断之后 V 后面的所有字符被删除，其中 Widnows 系统下的换行代表2个字符大小。</span><br><span class="line">fileObject.write([str])</span><br><span class="line">write() 方法用于向文件中写入指定字符串。</span><br><span class="line">在文件关闭前或缓冲区刷新前，字符串内容存储在缓冲区中，这时你在文件中是看不到写入的内容的。</span><br><span class="line">如果文件打开模式带 b，那写入文件内容时，str (参数)要用 encode 方法转为 bytes 形式，否则报错：TypeError: a bytes-like object is required, not &apos;str&apos;。</span><br><span class="line">fileObject.writelines([str])</span><br><span class="line">writelines() 方法用于向文件中写入一序列的字符串。这一序列字符串可以是由迭代对象产生的，如一个字符串列表。换行需要指定换行符 \n。</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line">实例</span><br><span class="line">filename = &apos;data.log&apos;</span><br><span class="line"># 打开文件(a+ 追加读写模式)</span><br><span class="line"># 用 with 关键字的方式打开文件，会自动关闭文件资源</span><br><span class="line">with open(filename, &apos;w+&apos;, encoding=&apos;utf-8&apos;) as file:</span><br><span class="line">    print(&apos;文件名称: &#123;&#125;&apos;.format(file.name))</span><br><span class="line">    print(&apos;文件编码: &#123;&#125;&apos;.format(file.encoding))</span><br><span class="line">    print(&apos;文件打开模式: &#123;&#125;&apos;.format(file.mode))</span><br><span class="line">    print(&apos;文件是否可读: &#123;&#125;&apos;.format(file.readable()))</span><br><span class="line">    print(&apos;文件是否可写: &#123;&#125;&apos;.format(file.writable()))</span><br><span class="line">    print(&apos;此时文件指针位置为: &#123;&#125;&apos;.format(file.tell()))</span><br><span class="line">    # 写入内容</span><br><span class="line">    num = file.write(&quot;第一行内容\n&quot;)</span><br><span class="line">    print(&apos;写入文件 &#123;&#125; 个字符&apos;.format(num))</span><br><span class="line">    # 文件指针在文件尾部，故无内容</span><br><span class="line">    print(file.readline(), file.tell())</span><br><span class="line">    # 改变文件指针到文件头部</span><br><span class="line">    file.seek(0)</span><br><span class="line">    # 改变文件指针后，读取到第一行内容</span><br><span class="line">    print(file.readline(), file.tell())</span><br><span class="line">    # 但文件指针的改变，却不会影响到写入的位置</span><br><span class="line">    file.write(&apos;第二次写入的内容\n&apos;)</span><br><span class="line">    # 文件指针又回到了文件尾</span><br><span class="line">    print(file.readline(), file.tell())</span><br><span class="line">    # file.read() 从当前文件指针位置读取指定长度的字符</span><br><span class="line">    file.seek(0)</span><br><span class="line">    print(file.read(9))</span><br><span class="line">    # 按行分割文件，返回字符串列表</span><br><span class="line">    file.seek(0)</span><br><span class="line">    print(file.readlines())</span><br><span class="line">    # 迭代文件对象，一行一个元素</span><br><span class="line">    file.seek(0)</span><br><span class="line">    for line in file:</span><br><span class="line">        print(line, end=&apos;&apos;)</span><br><span class="line"># 关闭文件资源</span><br><span class="line">if not file.closed:</span><br><span class="line">    file.close()</span><br><span class="line">输出：</span><br><span class="line">文件名称: data.log</span><br><span class="line">文件编码: utf-8</span><br><span class="line">文件打开模式: w+</span><br><span class="line">文件是否可读: True</span><br><span class="line">文件是否可写: True</span><br><span class="line">此时文件指针位置为: 0</span><br><span class="line">写入文件 6 个字符</span><br><span class="line"> 16</span><br><span class="line">第一行内容</span><br><span class="line"> 16</span><br><span class="line"> 41</span><br><span class="line">第一行内容</span><br><span class="line">第二次</span><br><span class="line">[&apos;第一行内容\n&apos;, &apos;第二次写入的内容\n&apos;]</span><br><span class="line">第一行内容</span><br><span class="line">第二次写入的内容</span><br></pre></td></tr></table></figure>
<h1 id="序列化"><a href="#序列化" class="headerlink" title="序列化"></a>序列化</h1><ul>
<li>在 Python 中 pickle 模块实现对数据的序列化和反序列化。pickle 支持任何数据类型，包括内置数据类型、函数、类、对象等。<h1 id="方法"><a href="#方法" class="headerlink" title="方法"></a>方法</h1></li>
</ul>
<h2 id="dump"><a href="#dump" class="headerlink" title="dump"></a>dump</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">将数据对象序列化后写入文件</span><br><span class="line">pickle.dump(obj, file, protocol=None, fix_imports=True)</span><br><span class="line">必填参数 obj 表示将要封装的对象。 必填参数 file 表示 obj 要写入的文件对象，file 必须以二进制可写模式打开，即wb。 可选参数 protocol 表示告知 pickle 使用的协议，支持的协议有 0,1,2,3，默认的协议是添加在 Python 3 中的协议3。</span><br></pre></td></tr></table></figure>
<h2 id="load"><a href="#load" class="headerlink" title="load"></a>load</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">从文件中读取内容并反序列化</span><br><span class="line">pickle.load(file, fix_imports=True, encoding=&apos;ASCII&apos;, errors=&apos;strict&apos;)</span><br><span class="line">必填参数 file 必须以二进制可读模式打开，即rb，其他都为可选参数。</span><br></pre></td></tr></table></figure>
<h2 id="dumps"><a href="#dumps" class="headerlink" title="dumps"></a>dumps</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">以字节对象形式返回封装的对象，不需要写入文件中</span><br><span class="line">pickle.dumps(obj, protocol=None, fix_imports=True)</span><br><span class="line">loads</span><br><span class="line">从字节对象中读取被封装的对象，并返回</span><br><span class="line">pickle.loads(bytes_object, fix_imports=True, encoding=&apos;ASCII&apos;, errors=&apos;strict&apos;)</span><br></pre></td></tr></table></figure>
<h2 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">import pickle</span><br><span class="line">data = [1, 2, 3]</span><br><span class="line"># 序列化数据并以字节对象返回</span><br><span class="line">dumps_obj = pickle.dumps(data)</span><br><span class="line">print(&apos;pickle.dumps():&apos;, dumps_obj)</span><br><span class="line"># 从字节对象中反序列化数据</span><br><span class="line">loads_data = pickle.loads(dumps_obj)</span><br><span class="line">print(&apos;pickle.loads():&apos;, loads_data)</span><br><span class="line">filename = &apos;data.log&apos;</span><br><span class="line"># 序列化数据到文件中</span><br><span class="line">with open(filename, &apos;wb&apos;) as file:</span><br><span class="line">    pickle.dump(data, file)</span><br><span class="line"># 从文件中加载并反序列化</span><br><span class="line">with open(filename, &apos;rb&apos;) as file:</span><br><span class="line">    load_data = pickle.load(file)</span><br><span class="line">    print(&apos;pickle.load():&apos;, load_data)</span><br><span class="line">输出：</span><br><span class="line">pickle.dumps(): b&apos;\x80\x03]q\x00(K\x01K\x02K\x03e.&apos;</span><br><span class="line">pickle.loads(): [1, 2, 3]</span><br><span class="line">pickle.load(): [1, 2, 3]</span><br></pre></td></tr></table></figure>
<h1 id="命名规范"><a href="#命名规范" class="headerlink" title="命名规范"></a>命名规范</h1><p><img src="http://wx4.sinaimg.cn/mw690/705e8c43gy1fuw5gt2cmsj20jo0cxgn2.jpg" alt="Python 之父 Guido 推荐的规范"></p>
<p><a href="http://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_style_rules/" target="_blank" rel="noopener">一份来自谷歌的 Python 风格规范</a></p>
</section>
    <!-- Tags START -->
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/blog/2018/09/03/Python-3-面向对象/">
        <span class="nav-arrow">← </span>
        
          Python-3-面向对象
        
      </a>
    
    
      <a class="nav-right" href="/blog/2018/09/03/Linux-Iptables-导入导出/">
        
          Linux-Iptables-导入导出
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    
      <!-- No Comment -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
    <strong class="toc-title">Catalog</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#文件操作"><span class="toc-nav-text">文件操作</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#打开文件"><span class="toc-nav-text">打开文件</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#文件对象方法"><span class="toc-nav-text">文件对象方法</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#序列化"><span class="toc-nav-text">序列化</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#方法"><span class="toc-nav-text">方法</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#dump"><span class="toc-nav-text">dump</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#load"><span class="toc-nav-text">load</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#dumps"><span class="toc-nav-text">dumps</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#实例"><span class="toc-nav-text">实例</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#命名规范"><span class="toc-nav-text">命名规范</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'git@gitee.com:sanyuanempire/blog.git/2018/09/03/Python-3-文件操作/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

     // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()
        
        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })

    // qrcode
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });

    // gitment
    var gitmentConfig = "";
    if (gitmentConfig !== 'undefined') {
      var gitment = new Gitment({
        id: "Python-3-文件操作",
        owner: "",
        repo: "",
        oauth: {
          client_id: "",
          client_secret: ""
        },
        theme: {
          render(state, instance) {
            const container = document.createElement('div')
            container.lang = "en-US"
            container.className = 'gitment-container gitment-root-container'
            container.appendChild(instance.renderHeader(state, instance))
            container.appendChild(instance.renderEditor(state, instance))
            container.appendChild(instance.renderComments(state, instance))
            container.appendChild(instance.renderFooter(state, instance))
            return container;
          }
        }
      })
      gitment.render(document.getElementById('comments'))
    }
  })();
</script>

<script>
  var disqus_shortname = '';
  
  var disqus_url = 'git@gitee.com:sanyuanempire/blog.git/2018/09/03/Python-3-文件操作/';
  
  (function(){
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    dsq.src = '//go.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>

    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
  <p class="copyright">
    &copy; 2018 | Proudly powered by <a href="https://sanyuanempire.gitee.io/blog" target="_blank">JinYan</a>
    <br>
    Theme by <a href="https://sanyuanempire.gitee.io/blog">JinYan</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("//cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("//cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>
<!-- Baidu Tongji -->

<script src="/blog/js/script.js"></script>

  </body>
</html>